<?php
//Connection statement
require_once('../Connections/cn.php');

// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

//start Trigger_CheckPasswords trigger
//remove this line if you want to edit the code by hand
function Trigger_CheckPasswords(&$tNG) {
  $myThrowError = new tNG_ThrowError($tNG);
  $myThrowError->setErrorMsg("Passwords do not match.");
  $myThrowError->setField("clave_usuario");
  $myThrowError->setFieldErrorMsg("The two passwords do not match.");
  return $myThrowError->Execute();
}
//end Trigger_CheckPasswords trigger

//start Trigger_CheckOldPassword trigger
//remove this line if you want to edit the code by hand
function Trigger_CheckOldPassword(&$tNG) {
  return Trigger_UpdatePassword_CheckOldPassword($tNG);
}
//end Trigger_CheckOldPassword trigger

// begin Recordset
$colname__rsClave = '-1';
if (isset($_SESSION['kt_login_user'])) {
  $colname__rsClave = $_SESSION['kt_login_user'];
}
$query_rsClave = sprintf("SELECT id_usuario, rut_persona, clave_usuario FROM usuario WHERE rut_persona = '%s'", $colname__rsClave);
$rsClave = $cn->SelectLimit($query_rsClave) or die($cn->ErrorMsg());
$totalRows_rsClave = $rsClave->RecordCount();
// end Recordset

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("clave_usuario", true, "text", "", "", "", "Debe ingresar la clave nueva.");
$tNGs->prepareValidation($formValidation);
// End trigger

// Make an update transaction instance
$upd_usuario = new tNG_update($cn);
$tNGs->addTransaction($upd_usuario);
// Register triggers
$upd_usuario->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_usuario->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_usuario->registerTrigger("END", "Trigger_Default_Redirect", 99, "?mod=panel");
$upd_usuario->registerConditionalTrigger("{POST.clave_usuario} != {POST.re_clave_usuario}", "BEFORE", "Trigger_CheckPasswords", 50);
$upd_usuario->registerTrigger("BEFORE", "Trigger_CheckOldPassword", 60);
// Add columns
$upd_usuario->setTable("usuario");
$upd_usuario->addColumn("clave_usuario", "STRING_TYPE", "POST", "clave_usuario");
$upd_usuario->setPrimaryKey("id_usuario", "NUMERIC_TYPE", "SESSION", "kt_login_user");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsusuario = $tNGs->getRecordset("usuario");
$totalRows_rsusuario = $rsusuario->RecordCount();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.6.0?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
</head>

<body>
<?php
	echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
  <table cellpadding="2" cellspacing="0" class="KT_tngtable">
    <tr>
      <td width="170" class="KT_th"><label for="clave_usuario">Clave actual: </label></td>
      <td width="167"><label>
        <input name="clave" type="text" id="clave" size="32">
      </label></td>
    </tr>
    <tr>
      <td class="KT_th">Clave de acceso:</td>
      <td width="167"><input type="password" name="clave_usuario" id="clave_usuario" value="" size="32" />
        <?php echo $tNGs->displayFieldHint("clave_usuario");?> <?php echo $tNGs->displayFieldError("usuario", "clave_usuario"); ?> </td>
    </tr>
    <tr>
      <td class="KT_th"><label for="re_clave_usuario">Repita la clave de acceso:</label></td>
      <td><input type="password" name="re_clave_usuario" id="re_clave_usuario" value="" size="32" />      </td>
    </tr>
    <tr class="KT_buttons">
      <td colspan="2"><input type="submit" name="KT_Update1" id="KT_Update1" value="Actualizar registro" />      </td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
$rsClave->Close();
?>
